/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package aviso.entity;

import java.io.Serializable;
import java.util.Collection;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;

/**
 *
 * @author avgusti
 */
@Entity
@NamedQueries({
    @NamedQuery(name = "File.countNameAndUser", query = "select count(f) from ImageFile f where "
    + "f.name=:name and f.userName.id=:userid"),
    @NamedQuery(name = "File.listByUser", query = "select f from ImageFile f where f.userName.id=:userid"),
    @NamedQuery(name = "File.loadEager", query = "select distinct f from ImageFile f left join fetch f.adverts a where f.id=:fileid")
})
public class ImageFile implements Serializable {

    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    private String name;
    private Integer width, height;
    @ManyToOne
    private UserName userName;
    @ManyToMany(mappedBy="files")
    private List<Advert> adverts;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getIds() {
        return "s" + id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public UserName getUserName() {
        return userName;
    }

    public void setUserName(UserName userName) {
        this.userName = userName;
    }

    public Integer getHeight() {
        return height;
    }

    public void setHeight(Integer height) {
        this.height = height;
    }

    public Integer getWidth() {
        return width;
    }

    public void setWidth(Integer width) {
        this.width = width;
    }

    public List<Advert> getAdverts() {
        return adverts;
    }

    public void setAdverts(List<Advert> adverts) {
        this.adverts = adverts;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        if (!(object instanceof ImageFile)) {
            return false;
        }
        ImageFile other = (ImageFile) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "aviso.entity.File[ id=" + id + " ]";
    }
}
